import { Component, OnInit } from '@angular/core';
import { MARKET_SALESMAN_ROLE, USER_ROLE_OPTION } from '../../constant/dictionary';
import { NzMessageService, NzModalRef } from 'ng-zorro-antd';
import { MarketFansService } from '@core/routes-services/market-fans.service';

@Component({
  selector: 'app-customer-origin-link',
  templateUrl: './customer-origin-link.component.html',
  styles: []
})
export class CustomerOriginLinkComponent implements OnInit {

  customerId:any = null;
  cusRelates: any [] = [];
  isLoading: boolean = false;
  marketSalesmanRole: any[] = MARKET_SALESMAN_ROLE;

  constructor(private modal: NzModalRef,
              public message: NzMessageService,
              public marketFansService: MarketFansService,) {
  }

  ngOnInit(): void {
    this.initCusRelates();
  }

  initCusRelates(){
    this.isLoading = true;
    this.marketFansService.relatesChain(this.customerId,{}).then((res)=>{
      console.log(res);
      if (res.status.toString().startsWith('20')) {
        this.cusRelates = res.data
      } else {
        this.message.warning(res.message);
      }
      this.isLoading = false;
    }, error => {
      this.message.error(error.message ? error.message : error.error);
      this.isLoading = false;
    });
  }

  close() {
    this.modal.destroy();
  }

}
